package com.scy.java.thread.threadloopoutput;

//该线程输出十次1
//要求交替输出
public class ThreadForNumber2 extends Thread {
    @Override
    public void run() {
        for (int i = 0; i < 10; i++) {
            synchronized (MyLock.objLock) {
                System.out.println("2");
                //唤醒另外一个线程
                MyLock.objLock.notify();
                try {
                    //让自己休眠，释放锁
                    MyLock.objLock.wait();
                } catch (InterruptedException e) {
                    throw new RuntimeException("当前执行线程被中断。");
                }
            }
        }
    }
}
